import java.util.ArrayList;
import java.util.List;
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class project {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int max=releaseTimes[0];
        for(int i=releaseTimes.length-1;i>0;i--){
            releaseTimes[i]=releaseTimes[i]-releaseTimes[i-1];
            max=Math.max(max,releaseTimes[i]);
        }
        char ch='a';
        for(int i=0;i<keysPressed.length();i++){
            if(releaseTimes[i]==max){
                ch=ch<keysPressed.charAt(i)?keysPressed.charAt(i):ch;
            }
        }
        return ch;
    }












    public TreeNode insertIntoMaxTree(TreeNode root, int val) {
        if(root==null||root.val<val){
            TreeNode tmp=new TreeNode(val);
            tmp.left=root;
            return tmp;
        }
        root.right=insertIntoMaxTree(root.right,val);
        return root;
    }





















    public int[] getSumAbsoluteDifferences(int[] nums) {
        int len=nums.length;
        int[] arr=new int[len];
        for(int i=0;i<len;i++){
            int tmp=0;
            for(int j=0;j<len;j++){
                if(i==j){
                    continue;
                }else{
                    tmp+=Math.abs(nums[i]-nums[j]);
                }
            }
            arr[i]=tmp;
        }
        return arr;
    }















    public int getSum(int a, int b) {
        while (b!=0){
            int tmp=(a&b)<<1;
            a=a^b;
            b=tmp;
        }
        return a;
    }















    public List<Integer> grayCode(int n) {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<1<<n;i++){
            list.add((i>>1)^i);
        }
        return list;
    }
}
